var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
import React, { useEffect, useState } from "react";
import { View, Text, Image } from "@tarojs/components";
import "./index.scss";
var common = {
    no_data: "https://cdn.yryz.com/lovelorn/image/fatelove/empty/no_data1_4.png",
    no_search: "https://cdn.yryz.com/lovelorn/image/fatelove/empty/no_search1_4.png",
    no_loverank: "https://cdn.yryz.com/lovelorn/image/fatelove/empty/no-loverank@2x1_4.png",
    no_love: "https://cdn.yryz.com/lovelorn/image/fatelove/empty/no_love@2x1_4.png",
    noAccountDetail: "https://cdn.yryz.com/lovelorn/image/fatelove/empty/no-account-detail1_4.png",
    buy_recod: "https://cdn.yryz.com/lovelorn/image/fatelove/common/buy_recod1_4.png"
};
var presets = {
    "no-data": {
        image: common.no_data,
        content: "暂无相关数据"
    },
    "no-search": {
        image: common.no_search,
        content: "暂无任何搜索记录～"
    },
    "no-loverank": {
        image: common.no_loverank,
        content: "暂无任何排行信息"
    },
    "no-love": {
        image: common.no_love,
        content: "暂无任何排行信息"
    },
    "no-detail-money": {
        image: common.noAccountDetail,
        content: "暂无收支记录～"
    },
    "buy-recod": {
        image: common.buy_recod,
        content: "暂无任何邀请记录～"
    }
};
var Message = function (_a) {
    var className = _a.className, image = _a.image, preset = _a.preset, title = _a.title, content = _a.content, actionTitle = _a.actionTitle, onAction = _a.onAction;
    var _b = __read(useState({}), 2), config = _b[0], setConfig = _b[1];
    var handleAction = function () {
        if (!onAction) {
            throw new Error("`onAction` is required if there is an action button.");
        }
        onAction();
    };
    useEffect(function () {
        if (preset) {
            setConfig(__assign(__assign(__assign(__assign({}, presets[preset]), (title ? { title: title } : {})), (content ? { content: content } : {})), (actionTitle ? { actionTitle: actionTitle } : {})));
        }
        else {
            setConfig({
                image: image,
                title: title,
                content: content,
                actionTitle: actionTitle
            });
        }
    }, [preset, image, title, content, actionTitle]);
    var renderImage = function () {
        return config.image ? React.createElement(Image, { src: config.image, className: "image" }) : null;
    };
    var renderTitle = function () {
        return config.title ? React.createElement(Text, { className: "title" }, config.title) : null;
    };
    var renderContent = function () {
        return config.content ? (React.createElement(Text, { className: "content" }, config.content)) : null;
    };
    var actionButton = function () {
        return actionTitle ? (React.createElement(View, { onClick: handleAction, className: "actionButton" },
            React.createElement(Text, { className: "actionTitle" }, actionTitle))) : null;
    };
    return (React.createElement(View, { className: "message-main " + className },
        renderImage(),
        renderTitle(),
        renderContent(),
        actionButton()));
};
export default Message;
